const path = require('path');
const fs = require('fs-extra');
var { entrys, htmlPlugin } = require('./utils.js')

var { CleanWebpackPlugin } = require('clean-webpack-plugin')

const config = {
    mode: "development", //  development

    entry: entrys,



    resolve: {
        extensions: [".js", ".json", ".jsx", ".css", ".scss", "less"],
        alias: {
            '@src': path.join(__dirname, '../src/'),
            '@pages': path.join(__dirname, '../src/pages'),
            '@service': path.join(__dirname, '../src/service'),
            '@node_modules': path.join(__dirname, '../node_modules')
        }
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/, // 匹配.js文件
            exclude: /node_modules/,
            use: 'babel-loader?cacheDirectory=true'
        },
        {
            test: /\.(css|scss|sass)$/,
            use: [{
                loader: "style-loader" // 将 JS 字符串生成为 style 节点
            }, {
                loader: 'css-loader'
            }, {
                loader: 'postcss-loader'
            }, {
                loader: 'sass-loader',
                options: {
                    implementation: require('sass')
                }
            }]
        },
        {
            test: /\.less$/,
            use: [
                'style-loader',
                'css-loader',
                'less-loader'
            ]
        },
        {
            test: /\.(eot|ttf|woff|svg|woff2)$/,
            use: 'file-loader'
        },
        {
            test: /\.(png|jpe?g|gif)$/,
            use: [
                {
                    loader: 'url-loader',
                    options: {
                        limit: 8192,
                        outputPath: 'static/imgs/',
                        name: '[name].[hash:7].[ext]'
                    }
                }
                ,
                {
                    loader: 'image-webpack-loader',// 压缩图片
                    options: {
                        bypassOnDebug: true,
                    }
                }
            ]
        }]
    },
    plugins: [
        new CleanWebpackPlugin(),
        ...htmlPlugin
    ]
};


fs.writeFile(path.join(__dirname, '../log/config/base.json'), JSON.stringify(config, null, '\t'), function () { });


module.exports = config;